package com.polaris.live.adapter.gift

import com.blankj.utilcode.util.ColorUtils
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterGiftSelectNumBinding

/**
 * GiftWallSelectNumAdapter
 *
 * @author Created by 半仙 on 2023/9/19/019 17:54
 */
class GiftWallSelectNumAdapter : BaseBindingAdapter<AdapterGiftSelectNumBinding, Int>() {

    private var selectPosition = 0

    override fun convert(holder: VBViewHolder<AdapterGiftSelectNumBinding>, item: Int) {
        val position = holder.absoluteAdapterPosition
        holder.vb.apply {
            giftSelectNum.text = "$item"
            if (position == selectPosition) {
                giftSelectBack.setBackgroundResource(R.drawable.r24_back_fe1849)
                giftSelectNum.setTextColor(ColorUtils.getColor(R.color.commonButtomTextColor))
            } else {
                giftSelectBack.background = null
                giftSelectNum.setTextColor(ColorUtils.getColor(R.color.fff_70))
            }
        }
    }

    fun setSelect(position: Int) {
        selectPosition = position
        notifyDataSetChanged()
    }

    fun clearSelected() {
        if (selectPosition == -1) {
            return
        }
        val index = selectPosition
        selectPosition = -1
        notifyItemChanged(index)
    }

}